import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class test {
    @Test
    public  void testFileInPut()throws Exception {
        FileInputStream inputStream = new FileInputStream("D:\\tfy\\test.txt");
        int b;
        while ((b = inputStream.read()) != -1) {
            System.out.println((char)b);
        }
        inputStream.close();
    }

    @Test
    public  void testFileInPut1()throws Exception {
        FileInputStream inputStream = new FileInputStream("D:\\tfy\\test.txt");
        int b;
        byte[] bytes = new byte[2];
        while ((b = inputStream.read(bytes)) != -1) {
           // System.out.println(b);
            System.out.println("======");
            System.out.println(new String(bytes));
        }
        inputStream.close();
    }

    @Test
    public  void testFileOutPut()throws Exception {
        FileOutputStream outputStream = new FileOutputStream("D:\\tfy\\test.txt");
        outputStream.write(98);
        outputStream.write(99);
        outputStream.flush();
        outputStream.close();
    }
    @Test
    public  void testFileOutPut1()throws Exception {
        FileOutputStream outputStream = new FileOutputStream("D:\\tfy\\test.txt");
        byte[] b = "我是java高手".getBytes();
        outputStream.write(b);
        outputStream.close();
    }


    @Test
    public  void filePhotoCopy() {
        FileInputStream inputStream = null;
        FileOutputStream outputStream = null;
        try {
            inputStream = new FileInputStream("D:\\tfy\\ttt.jpg");
            outputStream = new FileOutputStream("D:\\tfy\\tttcopy.jpg");
            byte[] b = new byte[1024];
            int i;
            while ((i = inputStream.read(b)) != -1) {
                outputStream.write(b,0,i);
                outputStream.flush();
            }
            System.out.println("拷贝完成");
        }  catch (Exception e) {
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }



}
